home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kbookmarkmenu.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  7.6 KB  |  266 lines

  1. //  -*- c-basic-offset:4; indent-tabs-mode:nil -*-
  2. // vim: set ts=4 sts=4 sw=4 et:
  3. /* This file is part of the KDE project
  4.    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  5.  
  6.    This library is free software; you can redistribute it and/or
  7.    modify it under the terms of the GNU Library General Public
  8.    License as published by the Free Software Foundation; either
  9.    version 2 of the License, or (at your option) any later version.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.    Library General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU Library General Public License
  17.    along with this library; see the file COPYING.LIB.  If not, write to
  18.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.    Boston, MA 02110-1301, USA.
  20. */
  21.  
  22. #ifndef __kbookmarkmenu_h__
  23. #define __kbookmarkmenu_h__
  24.  
  25. #include <sys/types.h>
  26.  
  27. #include <qptrlist.h>
  28. #include <qptrstack.h>
  29. #include <qobject.h>
  30. #include <qlistview.h>
  31.  
  32. #include <kdialogbase.h>
  33. #include <klocale.h>
  34. #include <kaction.h>
  35.  
  36. #include "kbookmark.h"
  37. #include "kbookmarkmanager.h"
  38.  
  39. class QString;
  40. class QPopupMenu;
  41. class QPushButton;
  42. class QListView;
  43. class KLineEdit;
  44. class KBookmark;
  45. class KBookmarkGroup;
  46. class KAction;
  47. class KActionMenu;
  48. class KActionCollection;
  49. class KBookmarkOwner;
  50. class KBookmarkMenu;
  51. class KPopupMenu;
  52.  
  53. namespace KIO { class Job; }
  54.  
  55. /**
  56.  * This class provides a bookmark menu.  It is typically used in
  57.  * cooperation with KActionMenu but doesn't have to be.
  58.  *
  59.  * If you use this class by itself, then it will use KDE defaults for
  60.  * everything -- the bookmark path, bookmark editor, bookmark launcher..
  61.  * everything.  These defaults reside in the classes
  62.  * KBookmarkOwner (editing bookmarks) and KBookmarkManager
  63.  * (almost everything else).  If you wish to change the defaults in
  64.  * any way, you must reimplement and instantiate those classes
  65.  * <em>before</em> this class is ever called.
  66.  *
  67.  * Using this class is very simple:
  68.  *
  69.  * 1) Create a popup menu (either KActionMenu or KPopupMenu will do)
  70.  * 2) Instantiate a new KBookmarkMenu object using the above popup
  71.  *    menu as a parameter
  72.  * 3) Insert your (now full) popup menu wherever you wish
  73.  *
  74.  * Again, if you wish to modify any defaults, the procedure is:
  75.  *
  76.  * 1a) Reimplement your own KBookmarkOwner
  77.  * 1b) Reimplement and instantiate your own KBookmarkManager
  78.  */
  79. class KIO_EXPORT KBookmarkMenu : public QObject
  80. {
  81.   Q_OBJECT
  82.   friend class KBookmarkMenuNSImporter;
  83.   friend class RMB;
  84. public:
  85.   /**
  86.    * Fills a bookmark menu
  87.    * (one instance of KBookmarkMenu is created for the toplevel menu,
  88.    *  but also one per submenu).
  89.    *
  90.    * @param mgr The bookmark manager to use (i.e. for reading and writing)
  91.    * @param owner implementation of the KBookmarkOwner callback interface.
  92.    * @param parentMenu menu to be filled
  93.    * @param collec parent collection for the KActions. 
  94.    *  Only used for other menus than the toplevel one.
  95.    * @param root true for the toplevel menu
  96.    * @param add true to show the "Add Bookmark" and "New Folder" entries
  97.    * @param parentAddress the address of the group containing the items
  98.    *  that we want to show.
  99.    * @see KBookmark::address.
  100.    * Be careful :
  101.    * A _null_ parentAddress denotes a NS-bookmark menu.
  102.    * An _empty_ parentAddress denotes the toplevel bookmark menu
  103.    */
  104.   KBookmarkMenu( KBookmarkManager* mgr,
  105.                  KBookmarkOwner * owner, KPopupMenu * parentMenu,
  106.                  KActionCollection * collec, bool root, bool add = true,
  107.                  const QString & parentAddress = "" );
  108.  
  109.   ~KBookmarkMenu();
  110.  
  111.   /**
  112.    * Even if you think you need to use this, you are probably wrong.
  113.    * It fills a bookmark menu starting a given KBookmark.
  114.    * This is public for KBookmarkBar.
  115.    */
  116.   void fillBookmarkMenu();
  117.  
  118.   /**
  119.    * Call ensureUpToDate() if you need KBookmarkMenu to adjust to its 
  120.    * final size before it is executed.
  121.    **/
  122.   void ensureUpToDate();
  123.  
  124.   /**
  125.    * Structure used for storing information about 
  126.    * the dynamic menu setting
  127.    * @since 3.2
  128.    */
  129.   // TODO - transform into class
  130.   struct DynMenuInfo {
  131.      bool show;
  132.      QString location;
  133.      QString type;
  134.      QString name;
  135.      class DynMenuInfoPrivate *d;
  136.   };
  137.  
  138.   /**
  139.    * @return dynmenu info block for the given dynmenu name
  140.    * @since 3.2
  141.    */
  142.   static DynMenuInfo showDynamicBookmarks( const QString &id );
  143.  
  144.   /**
  145.    * Shows an extra menu for the given bookmarks file and type. 
  146.    * Upgrades from option inside XBEL to option in rc file
  147.    * on first call of this function.
  148.    * @param id the unique identification for the dynamic menu
  149.    * @param info a DynMenuInfo struct containing the to be added/modified data
  150.    * @since 3.2
  151.    */
  152.   static void setDynamicBookmarks( const QString &id, const DynMenuInfo &info );
  153.  
  154.   /**
  155.    * @return list of dynamic menu ids
  156.    * @since 3.2
  157.    */
  158.   static QStringList dynamicBookmarksList();
  159.  
  160. signals:
  161.   void aboutToShowContextMenu( const KBookmark &, QPopupMenu * );
  162.   /**
  163.    * @since 3.4
  164.    */
  165.   void openBookmark( const QString& url, Qt::ButtonState state );
  166.  
  167. public slots: // public for bookmark bar
  168.   void slotBookmarksChanged( const QString & );
  169.  
  170. protected slots:
  171.   void slotAboutToShow();
  172.   void slotAboutToShowContextMenu( KPopupMenu *, int, QPopupMenu * );
  173.   void slotActionHighlighted( KAction * );
  174.  
  175.   void slotRMBActionRemove( int );
  176.   void slotRMBActionInsert( int );
  177.   void slotRMBActionCopyLocation( int );
  178.   void slotRMBActionEditAt( int );
  179.   void slotRMBActionProperties( int );
  180.  
  181.   void slotBookmarkSelected();
  182.   /**
  183.    * @ since 3.4
  184.    */
  185.   void slotBookmarkSelected( KAction::ActivationReason reason, Qt::ButtonState state );
  186.   void slotAddBookmarksList();
  187.   void slotAddBookmark();
  188.   void slotNewFolder();
  189.  
  190.   /**
  191.    * load Netscape's bookmarks
  192.    */
  193.   void slotNSLoad();
  194.  
  195. protected:
  196.   KExtendedBookmarkOwner* extOwner();
  197.   void refill();
  198.   void addAddBookmark();
  199.   void addAddBookmarksList();
  200.   void addEditBookmarks();
  201.   void addNewFolder();
  202.  
  203.   void fillContextMenu( QPopupMenu *, const QString &, int );
  204.  
  205.   bool m_bIsRoot:1;
  206.   bool m_bAddBookmark:1;
  207.   bool m_bDirty:1;
  208.   bool m_bNSBookmark:1;
  209.   bool m_bAddShortcuts:1;
  210.  
  211.   KBookmarkManager * m_pManager;
  212.   KBookmarkOwner *m_pOwner;
  213.   /**
  214.    * The menu in which we plug our actions.
  215.    * Supplied in the constructor.
  216.    */
  217.   KPopupMenu * m_parentMenu;
  218.   /**
  219.    * List of our sub menus
  220.    */
  221.   QPtrList<KBookmarkMenu> m_lstSubMenus;
  222.   KActionCollection * m_actionCollection;
  223.   /**
  224.    * List of our actions.
  225.    */
  226.   QPtrList<KAction> m_actions;
  227.   /**
  228.    * Parent bookmark for this menu.
  229.    */
  230.   QString m_parentAddress;
  231.  
  232.   // TODO make non static!
  233.   static QString s_highlightedAddress;
  234.   static QString s_highlightedImportLocation;
  235.   static QString s_highlightedImportType;
  236. };
  237.  
  238. /**
  239.  * A class connected to KNSBookmarkImporter, to fill KActionMenus.
  240.  */
  241. class KIO_EXPORT KBookmarkMenuNSImporter : public QObject
  242. {
  243.   Q_OBJECT
  244. public:
  245.   KBookmarkMenuNSImporter( KBookmarkManager* mgr, KBookmarkMenu * menu, KActionCollection * act ) :
  246.      m_menu(menu), m_actionCollection(act), m_pManager(mgr) {}
  247.  
  248.   void openNSBookmarks();
  249.   void openBookmarks( const QString &location, const QString &type );
  250.   void connectToImporter( const QObject &importer );
  251.  
  252. protected slots:
  253.   void newBookmark( const QString & text, const QCString & url, const QString & );
  254.   void newFolder( const QString & text, bool, const QString & );
  255.   void newSeparator();
  256.   void endFolder();
  257.  
  258. protected:
  259.   QPtrStack<KBookmarkMenu> mstack;
  260.   KBookmarkMenu * m_menu;
  261.   KActionCollection * m_actionCollection;
  262.   KBookmarkManager* m_pManager;
  263. };
  264.  
  265. #endif
  266.